<template>
  <div class="md-new-detail-page-component">
    <!-- 头部 -->
    <MdDetailHeaderClassComponent :title="articleInfo.title" />
    <div class="n-box">
      <div class="n-left" v-html="articleInfo.content"></div>
      <div class="n-right" v-if="rid != 3 && rid != 4 && rid != 5">
        <b>相关资讯</b>
        <ul v-if="selectArticleList.length">
          <li v-for="(item, index) in selectArticleList" :key="index" @click="handleClick(item)">
            <!-- <div class="c-img">
              <img src="../assets/img/s1.jpeg" alt="">
            </div> -->
            <div class="c-type-box">
              <p class="c-tit">{{item.title}}</p>
              <!-- <p class="view-p-count">
                <i class="el-icon-user"></i>
                <span>2023.07.23</span>
              </p> -->
            </div>
          </li>
        </ul>
        <p v-else class="no-data">暂无数据</p>
      </div>
    </div>
  </div>
</template>
<script>
import { selectArticleInfo, selectArticleReferral } from '@/axios/news'
import MdDetailHeaderClassComponent from '../components/class/mdDetailHeader/index.vue'
export default {
  name: 'mdNewDetailPageComponent',
  data () {
    return {
      rid: '',
      articleInfo: {
        title: '',
        content: '',
        createTime: ''
      },
      selectArticleList: []
    }
  },
  watch: {
    '$route.query': {
      handler (val) {
        this.rid = val.rid
        this.selectArticleInfo(val.rid)
      },
      deep: true,
      immediate: true
    }
  },
  created () {
    this.selectArticleReferral()
  },
  methods: {
    async selectArticleInfo (rid) {
      const res = await selectArticleInfo(rid)
      if (res.code === 200) {
        // console.log(res)
        this.articleInfo = res.data
      }
    },
    async selectArticleReferral () {
      const res = await selectArticleReferral()
      if (res.code === 200) {
        this.selectArticleList = res.data
      }
    },
    handleClick (item) {
      this.$router.replace({
        path: '/newsDetail',
        query: {
          rid: item.rid
        }
      })
    }
  },
  components: {
    MdDetailHeaderClassComponent
  }
}
</script>
<style lang="less" scoped>
.md-new-detail-page-component {
  width: 100%;
  background: #fff;
  .n-box {
    width: 1152px;
    margin: 0 auto;
    display: flex;
    padding: 30px 0;
  }
  .n-left {
    flex: 1;
    margin-right: 20px;
    box-shadow: 0 4px 8px 0 rgba(28,31,33,.1);
    border-radius: 8px;
    padding: 20px 30px;
    border-radius: 8px;
    h1, h2, h3, h4, h5, h6 {
      margin: 10px 0 !important;
    }
    p {
      color: #333;
      font-size: 14px;
      line-height: 2;
      text-indent: 2em;
    }
    img {
      width: 100%;
      margin: 10px 0;
    }
  }
  .n-right {
    width: 328px;
    flex-shrink: 0;
    margin-bottom: 30px;
    box-shadow: 0 4px 8px 0 rgba(28,31,33,.1);
    border-radius: 8px;
    padding: 20px 15px 10px;
    max-height: 400px;
    b {
      color: @md-primary-color;
      margin-top: 20px;
    }
    ul {
      // padding: 5px;
      box-sizing: border-box;
      li {
        display: flex;
        padding: 10px;
        border-bottom: 1px solid rgba(43,51,59,0.1);
        &:hover {
          .c-type-box {
            .c-tit {
              color: @md-primary-color;
            }
          }
        }
        &:last-child {
          margin-bottom: 0;
          border-bottom: none;
        }
        .c-img {
          width: 80px;
          height: 60px;
          border-radius: 6px;
          overflow: hidden;
          position: relative;
          flex-shrink: 0;
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
        .c-type-box {
          flex: 1;
          // height: 60px;
          margin-left: 10px;
          overflow: hidden;
          .c-tit {
            width: 100%;
            padding-top: 8px;
            font-size: 14px;
            // height: 24px;
            // line-height: 24px;
            margin-bottom: 4px;
            cursor: pointer;
            color: #545C63;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
          .view-p-count {
            display: flex;
            align-items: center;
            color: #545C63;
            font-size: 12px;
            margin-top: 5px;
            i {
              margin-right: 3px;
              font-size: 14px;
            }
          }
        }
      }
    }
  }
}
.no-data {
  color: #999;
  font-size: 12px;
  padding: 30px 0;
  text-align: center;
}
</style>